package com.lbssoft.gpsbd.service.impl;

import com.lbssoft.gpsbd.dao.LayerMapper;
import com.lbssoft.gpsbd.model.Layer;
import com.lbssoft.gpsbd.model.LayerPermission;
import com.lbssoft.gpsbd.model.vo.UserVo;
import com.lbssoft.gpsbd.service.LayerService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by nczc on 2018/5/30.
 */
@Service
public class LayerServiceImpl implements LayerService {

    @Autowired
    public LayerMapper layerMapper;

    @Override
    public List<Layer> list(long userId) {
        return layerMapper.list(userId);
    }

    @Override
    public void update(Layer layer) {
        layerMapper.update(layer);
    }

    @Override
    public void add(Layer layer) {
        UserVo user = (UserVo) SecurityUtils.getSubject().getPrincipal();
        layerMapper.add(layer);
        LayerPermission layerPermission = new LayerPermission();
        layerPermission.setLayerId(layer.getId());
        layerPermission.setUserId(user.getId());
        layerMapper.addUserLayer(layerPermission);
    }

    @Override
    public void delete(int id) {
        layerMapper.delete(id);
    }
}
